﻿using Hello.Api.Filters;
using Hello.Api.Orders.Contracts;
using MassTransit;

namespace Hello.Api.Orders.Consumers
{
    public class VerifyOrderConsumer : IConsumer<VerifyOrder>
    {
        public async Task Consume(ConsumeContext<VerifyOrder> context)
        {
            if(!context.IsResponseAccepted<Email>())
            {
                throw new ArgumentOutOfRangeException(nameof(context));
            }

            if (context.Message.Id==1)
            {
                await context.RespondAsync<OrderResult>(new OrderResult
                {
                    Id = context.Message.Id,
                    Amount = 30,
                    CustomerName = "Gigi Devinson"
                });
                return;
            }
            else
            {
                await context.RespondAsync<OrderNotFoundResult>(new OrderNotFoundResult
                {
                    Message = $"Order with Id: {context.Message.Id} not found, Sorry!"
                });
            }
        }
    }
}
